﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Models;

namespace UI
{
    public partial class UpdateCar : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DropDownList1.DataSource = new CarTypeBLL().Dat();
                DropDownList1.DataTextField = "TypeName";
                DropDownList1.DataValueField = "TypeID";
                DropDownList1.DataBind();
                string ss = Request.Cookies["Name"].Value;
                CarInfoModels c = new CarInfoBLL().C(ss);
                this.TextBox1.Text = c.CarName;
                this.TextBox2.Text =( c.CarPrice)+"";
                this.TextBox3.Text = c.Desc;
                this.TextBox4.Text = c.Place;
                this.DropDownList1.Text = c.TypeID+"";
            }

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string ss = Request.Cookies["Name"].Value;
            CarInfoModels c = new CarInfoModels() {
                CarName = this.TextBox1.Text,
                CarPrice =Convert.ToInt32( this.TextBox2.Text),
                TypeID = Convert.ToInt32( this.DropDownList1.Text),
                Desc = this.TextBox3.Text,
                Place = this.TextBox4.Text
            };
            if (new CarInfoBLL().Update(c,ss))
            {
                Response.Redirect("CarInfoUI.aspx");
            }
            else
            {
                Response.Write("修改失败！");
            }
        }
    }
}